$(function () {
    //************购买成功**************//
    $(".yyc>p>a").click(function () {
        $(".yyc").hide();
    })
    //**********购买成功结束**************//
    //点击我的
    $("footer>a:last-of-type").click(function () {
        $("#gerenxinxi>article>.yycg>p>a").attr("href", "#wode");
    })
    var http = "http://file.ixinyun.cn/";
    new Ajax("/index/banner").getJson(function (json) { //追加轮播图图片

        $.each(json, function (k, v) {
            $("#shouye>article>.lunbotu>ul").append("<li dataid=" + v["id"] + ">" + "<a href=" + "#" + "kechengzhuti" + ">" + "<img src=" + http + v["ico"] + ">" + "</a>" + "</li>");
        });
        var wh = $(window).width();
        var liLen = $('#shouye>article>.lunbotu>ul>li').length;
        var firstLi = $('#shouye>article>.lunbotu>ul>li:first').clone();
        var lastLi = $('#shouye>article>.lunbotu>ul>li:last').clone();
        var moveX, t, ratio = 1;
        $('#shouye>article>.lunbotu>ul').append(firstLi).prepend(lastLi);
        $('#shouye>article>.lunbotu>ul').on('touchstart', function (e) {
            clearInterval(t);
            var touchX = e.originalEvent.targetTouches[0].pageX - $(this).offset().left;
            $('#shouye>article>.lunbotu>ul').on('touchmove', function (e) {
                moveX = e.originalEvent.targetTouches[0].pageX - touchX;
                $(this).css('margin-left', moveX + "px");
            });
        });
        $('#shouye>article>.lunbotu>ul').on('touchend', function () {
            timer();
            ratio = Math.abs(Math.round(moveX / wh));
            $(this).stop().animate({
                'margin-left': ratio * -wh
            }, 500, function () {
                if (ratio >= liLen + 1) {
                    $(this).css('margin-left', -wh);
                    ratio = 1;
                } else if (ratio === 0) {
                    $(this).css('margin-left', -(liLen) * wh);
                    ratio = -(liLen);
                }
            });
        });

        function timer() {
            t = setInterval(function () {
                ratio++;
                $('#shouye>article>.lunbotu>ul').stop().animate({
                    'margin-left': ratio * -wh
                }, 1500, function () {
                    if (ratio == liLen + 1) {
                        $(this).css('margin-left', -wh);
                        ratio = 1;
                    }
                });
            }, 3000);
        }
        timer();
    });
    
    var xiaojie = $("#kechengzhuti>article>.banner_3>.video>ul"); //课程小节
    //轮播图跳转详情
    $("#shouye>article>.lunbotu>ul").on("click", "li", function () { //只需要找到你点击的是哪个ul里面的就行
        var dataid = $(this).attr("dataid");
        $("#kechengzhuti>article>.banner_3>.d1>p").remove();
        $("#kechengzhuti>article>.banner_3>.d4>p").remove();
        $("#kechengzhuti>article>.banner_3>.d3>p").remove();
        $("#kechengzhuti>article>.banner_3>.d2>.daoshijieshao>p").remove();
        new Ajax("/index/kecheng").keyvalue("id", dataid).keyvalue("type", 1).getJson(function (json) {

            $.each(json, function (k, v) {

                xiaojie.empty(); //清空原有内容
                course(v); //写入视频
                txt = jieci(v["totalnode"]); //写入有多少节小课
                paixu(v, v["id"], 36);
                xiaojie.html(txt);

            });
        });
    });
   /**********************************************************************/
    //首页标签切换
    //方法封装在tianchong.js中
    //建立缓存
    var huancun = "";
    new Ajax("/index/kecheng_query").getJson(function (json) {
        jso =json;
        huancun = json;
    })
    var al = $(".daohanglan a").length;
    $(".daohanglan a").click(function () {
    	    if($(this).text()=="首页"){
    	    	$("#shouye>article>.gy").show();
    	    	$("#shouye>article>.yunqi").hide();
    	    }else{
    	    	$("#shouye>article>.gy").hide();
    	    	$("#shouye>article>.yunqi").show();
    	    }
            $(this).addClass("intro").siblings().removeClass("intro");
            var dataid = $(this).attr("dataid");
            $("#shouye>article>.yunqi>.d5>ul").empty();
        //    对应的标签赋值		
        var a = 0;
        $.each(huancun, function (k, v) {
            a = qiehuan(v, a, dataid);
        })
    });
    //课程培训标签切换
    $("#kechengpeixun>article>.nev>a").click(function(){
    	$(this).addClass("intro");
    	$(this).siblings().removeClass("intro");
    	if($(this).text()=="线下培训"){
    		
    		jingqi_lishi();
    	}
    })
    /*********************************************************************/
    $("#shouye>article>.yunqi>.d5>ul").on("click", "li", function () { //只需要找到你点击的是哪个ul里面的就行
        var dataid = $(this).attr("dataid");
        $("#kechengzhuti>article>.banner_3>.d1>p").remove();
        $("#kechengzhuti>article>.banner_3>.d4>p").remove();
        $("#kechengzhuti>article>.banner_3>.d2>.daoshijieshao>p").remove();
        new Ajax("/index/kecheng").getJson(function (json) {
            $.each(json, function (k, v) {
                if (v["canyurenshu"] == "" || v["canyurenshu"] == undefined) {
                    v["canyurenshu"] = 0;
                }
                if (v["id"] == dataid) {
                    xiaojie.empty(); //清空原有内容
                    course(v); //写入视频
                    txt = jieci(v["totalnode"]); //写入有多少节小课
                    paixu(v, v["id"], 63);
                    xiaojie.html(txt);

                }
            });

        });
    });

  

    //------------------精彩视频-------------------//

//  $("footer").on("click", "#px", function () { //只需要找到你点击的是哪个ul里面的就行
//
//      var dataid = $(this).attr("dataid");
//      new Ajax("/index/kechengjingcai").getJson(function (json) {
//          $.each(json, function (k, v) {
//              if (v["canyurenshu"] == "" || v["canyurenshu"] == undefined) {
//                  v["canyurenshu"] = 0;
//              }
//              if (v["id"] == dataid) {
//                  xiaojie.empty(); //清空原有内容
//                  course(v); //写入视频
//                  txt = jieci(v["totalnode"]); //写入有多少节小课
//                  paixu(v, v["id"], 63);
//                  xiaojie.html(txt);
//              }
//          });
//
//      });
//  });

    //---------！---------精彩视频---------！----------//
    //---------------------线下培训---------------------//
    $("#kechengpeixun>article>.nev>a").eq(0).click(function () {

        $(".d4").show();
        $(".xixi").hide();
        $(".cha").hide();
    });
    $("#kechengpeixun>article>.nev>a").eq(1).click(function () {
        $(".xixi").show();
        $(".d4").hide();
        $(".cha").hide();
    });
    $("#kechengpeixun>article>.nev>a").eq(2).click(function () {
        $(".cha").show();
        $(".d4").hide();
        $(".xixi").hide();
    });

    $("#kechengpeixun>article>.xixi>.xianxia>.yuyue>ul>li>h4").click(function () {
        $(this).css("background", "#f0f0f0").text("已经报名").css("color", "#fff");
        $("#kechengpeixun>article>.yycg").show();
        $("#kechengpeixun>article>.yycg>p").eq(0).show();

    });
    $("#kechengpeixun>article>.yycg>p>button").click(function () {

        $("#kechengpeixun>article>.yycg").hide();
        $("#kechengpeixun>article>.yycg>p").eq(0).hide();

    })

    //---------------------线下培训结束------------------//


    //问答
    $("#wenda>article>.zt>ul>li>.p2").click(function () {
        $("#wenda>article>.zf").show();
        $("body").addClass("yc");
        $("footer").hide();
    });
    $("#wenda>article>.zf>h1").click(function () {
        $("#wenda>article>.zf").hide();
        $("body").removeClass("yc");
        $("footer").show();
    });
    
    
    
    //置顶
    $("#wenda>article>.zt>ul").on('click', '.img2', function (event) {
        if ($(this).hasClass("yanse")) {
            $(this).removeClass("yanse");
        } else {
            event.preventDefault;
            var parent = $(this).parent();
            var parents = $(this).parents("#wenda>article>.zt>ul");
            switch (true) {
                case $(this).is(".img2"):
                    parents.prepend(parent);
                    $(this).addClass("yanse");
                    break;
            }
        }

    });
//点击商城按钮开始
 $("#sc").click(function(){
    //------------------商场的轮播图------------------//
    var http = "http://file.ixinyun.cn/";
    new Ajax("/mallbanner").getJson(function (json) { //追加轮播图图片
        $.each(json, function (k, v) {
            $("#shangcheng>article>.lunbotu>ul").append("<li dataid=" + v["id"] + ">" + "<a href=" + "#" + "" + ">" + "<img src=" + http + v["picture"] + ">" + "</a>" + "</li>");
        });
        var wh = $(window).width();
        var liLen = $('#shangcheng>article>.lunbotu>ul>li').length;
        var firstLi = $('#shangcheng>article>.lunbotu>ul>li:first').clone();
        var lastLi = $('#shangcheng>article>.lunbotu>ul>li:last').clone();
        var moveX, t, ratio = 1;
        $('#shangcheng>article>.lunbotu>ul').append(firstLi).prepend(lastLi);
        $('#shangcheng>article>.lunbotu>ul').on('touchstart', function (e) {
            clearInterval(t);
            var touchX = e.originalEvent.targetTouches[0].pageX - $(this).offset().left;
            $('#shangcheng>article>.lunbotu>ul').on('touchmove', function (e) {
                moveX = e.originalEvent.targetTouches[0].pageX - touchX;
                $(this).css('margin-left', moveX + "px");
            });
        });
        $('#shangcheng>article>.lunbotu>ul').on('touchend', function () {
            timer();
            ratio = Math.abs(Math.round(moveX / wh));
            $(this).stop().animate({
                'margin-left': ratio * -wh
            }, 500, function () {
                if (ratio >= liLen + 1) {
                    $(this).css('margin-left', -wh);
                    ratio = 1;
                } else if (ratio === 0) {
                    $(this).css('margin-left', -(liLen) * wh);
                    ratio = -(liLen);
                }
            });
        });

        function timer() {
            t = setInterval(function () {
                ratio++;
                $('#shangcheng>article>.lunbotu>ul').stop().animate({
                    'margin-left': ratio * -wh
                }, 500, function () {
                    if (ratio == liLen + 1) {
                        $(this).css('margin-left', -wh);
                        ratio = 1;
                    }
                });
            }, 4000);
        }
        timer();
    });
    //-------！-----------商场的轮播图结束----------！--------//

    //--------------------- 限时特价-------------------------//
    var http = "http://file.ixinyun.cn/";
    new Ajax("/mallbanner").getJson(function (json) { //追加轮播图图片
        $.each
        var wh = $(window).width();
        var liLen = $('#shangcheng>article>.tejia_tu>ul>li').length;
        var firstLi = $('#shangcheng>article>.tejia_tu>ul>li:first').clone();
        var lastLi = $('#shangcheng>article>.tejia_tu>ul>li:last').clone();
        var moveX, t, ratio = 1;
        $('#shangcheng>article>.tejia_tu>ul').append(firstLi).prepend(lastLi);
        $('#shangcheng>article>.tejia_tu>ul').on('touchstart', function (e) {
            clearInterval(t);
            var touchX = e.originalEvent.targetTouches[0].pageX - $(this).offset().left;
            $('#shangcheng>article>.tejia_tu>ul').on('touchmove', function (e) {
                moveX = e.originalEvent.targetTouches[0].pageX - touchX;
                $(this).css('margin-left', moveX + "px");
            });
        });
        $('#shangcheng>article>.tejia_tu>ul').on('touchend', function () {
            timer();
            ratio = Math.abs(Math.round(moveX / wh));
            $(this).stop().animate({
                'margin-left': ratio * -wh
            }, 500, function () {
                if (ratio >= liLen + 1) {
                    $(this).css('margin-left', -wh);
                    ratio = 1;
                } else if (ratio === 0) {
                    $(this).css('margin-left', -(liLen) * wh);
                    ratio = -(liLen);
                }
                $('#shangcheng>article>.tejia_tu>ol>li').eq(ratio + 1).addClass('blue').siblings().removeClass('blue');
            });
        });

        function timer() {
            t = setInterval(function () {
                ratio++;
                $('#shangcheng>article>.tejia_tu>ul').stop().animate({
                    'margin-left': ratio * -wh
                }, 500, function () {
                    if (ratio == liLen + 1) {
                        $(this).css('margin-left', -wh);
                        ratio = 1;
                    }
                    $('#shangcheng>article>.tejia_tu>ol>li').eq(ratio - 1).addClass('blue').siblings().removeClass('blue');
                });

            }, 4000);
        }
        timer();
    });

    //--------------！---限时特价结束---！------------------//
    //-----------------瑜伽服饰---------------------//
    //获得跳转的内容
    $("#fushi>article>.shangpin>ul>li").hover(function () {
        $(this).addClass("xia").siblings().removeClass("xia");
    });
    //-----------！------瑜伽服饰结束-------！--------------//

    //--------------------- 商品详情-------------------------//
    var http = "http://file.ixinyun.cn/";
    new Ajax("/index/banner").getJson(function (json) { //追加轮播图图片
        var wh = $(window).width();
        var liLen = $('#shangpingxiang>article>.sc_wu>ul>li').length;
        var firstLi = $('#shangpingxiang>article>.sc_wu>ul>li:first').clone();
        var lastLi = $('#shangpingxiang>article>.sc_wu>ul>li:last').clone();
        var moveX, t, ratio = 1;
        $('#shangpingxiang>article>.sc_wu>ul').append(firstLi).prepend(lastLi);
        $('#shangpingxiang>article>.sc_wu>ul').on('touchstart', function (e) {
            clearInterval(t);
            var touchX = e.originalEvent.targetTouches[0].pageX - $(this).offset().left;
            $('#shangpingxiang>article>.sc_wu>ul').on('touchmove', function (e) {
                moveX = e.originalEvent.targetTouches[0].pageX - touchX;
                $(this).css('margin-left', moveX + "px");
            });
        });
        $('#shangpingxiang>article>.sc_wu>ul').on('touchend', function () {
            timer();
            ratio = Math.abs(Math.round(moveX / wh));
            $(this).stop().animate({
                'margin-left': ratio * -wh
            }, 500, function () {
                if (ratio >= liLen + 1) {
                    $(this).css('margin-left', -wh);
                    ratio = 1;
                } else if (ratio === 0) {
                    $(this).css('margin-left', -(liLen) * wh);
                    ratio = -(liLen);
                }
                $('#shangpingxiang>article>.sc_wu>ol>li').eq(ratio + 1).addClass('blue').siblings().removeClass('blue');
            });
        });

        function timer() {
            t = setInterval(function () {
                ratio++;
                $('#shangpingxiang>article>.sc_wu>ul').stop().animate({
                    'margin-left': ratio * -wh
                }, 500, function () {
                    if (ratio == liLen + 1) {
                        $(this).css('margin-left', -wh);
                        ratio = 1;
                    }
                    $('#shangpingxiang>article>.sc_wu>ol>li').eq(ratio - 1).addClass('blue').siblings().removeClass('blue');
                });

            }, 4000);
        }
        timer();
    });
    $("#shangpingxiang>article>.sc_guxiang>ul>li>ul>li").click(function () {
        $(this).addClass("sc_dian").siblings().removeClass("sc_dian");
    })
    //--------------！---商品详情结束---！------------------//

    //---------------------搜索------------------------//
    new Ajax("/mallsearch").keyvalue("type", "type").getJson(function (json) {
        $.each(json, function (k, v) {

        })
    })

    //------------！---------搜索结束----------！-------------//

 })//点击商城按钮结束

})

